//
//  ViewController.m
//  TestScrollView
//
//  Created by gzjd on 2017/11/16.
//  Copyright © 2017年 gzjd. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UIScrollViewDelegate>{
    UIPageControl *pControl;
    UIScrollView *sv;
}
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    sv=[[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 375, 667)];
    sv.backgroundColor=[UIColor yellowColor];
    [self.view addSubview:sv];
    //设置大小（多大才能翻下图）
    sv.contentSize=CGSizeMake(375*3, 667);
    //把图片装进去
    for(int i=1;i<=3;i++){
        NSString *name=[NSString stringWithFormat:@"%d.jpg",i];
        UIImage *image=[UIImage imageNamed:name];
        UIImageView *imageV=[[UIImageView alloc] initWithFrame:CGRectMake(375*(i-1), 0, 375, 667)];
        imageV.image=image;
        [sv addSubview:imageV];
        
    }
    //分页显示图片
    sv.pagingEnabled=YES;
    //是否与许反弹
    sv.bounces=NO;
    //修改滚动条的大小
    sv.indicatorStyle=UIScrollViewIndicatorStyleBlack;
    //隐藏滚动条
    sv.showsHorizontalScrollIndicator=NO;
    //默认初始化显示第二章图片
    sv.contentOffset=CGPointMake(375*2, 0);
    //添加代理接口
    sv.delegate=self;
    //创建下面三个小点
    pControl=[[UIPageControl alloc]initWithFrame:CGRectMake(0, 600, 375, 50)];
    // pControl.backgroundColor=[UIColor redColor];
    [self.view addSubview:pControl];
    pControl.numberOfPages=3;
    pControl.currentPageIndicatorTintColor=[UIColor yellowColor];
    pControl.pageIndicatorTintColor=[UIColor redColor];
    [pControl addTarget:self action:@selector(pageCon:) forControlEvents:UIControlEventValueChanged];
    
}
-(void)pageCon:(UIPageControl*)p{
///NSLog(@"-------->%d",p.currentPage);
   
    
    //sv.contentOffset=CGPointMake(375*p.currentPage, 0);
    [sv setContentOffset:CGPointMake(375*p.currentPage, 0) animated:YES];
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    NSLog(@"动了");
    
}
-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
    NSLog(@"开始推追");
    
}
-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView{
    NSLog(@"结束托追");
    
}
-(void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView{
    NSLog(@"开始建树");
}
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    NSLog(@"结束减速");
    NSInteger number=(int)scrollView.contentOffset.x/375;
    pControl.currentPage=number;
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
